﻿using DAL;
using DAL.DataProvider;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace BAL
{
    public class HoaDonBAO
    {
        public static HoaDonDAO hoadonDAO = new HoaDonDAO();
        public void InsertHoaDon(HoaDon hoadon)
        {
            Console.WriteLine("Nhap");
            bool flag=false;
            SqlCommand cmd = new SqlCommand("Select MaQuay from QuayThuNgan", DataAccess.GetConnection());
            SqlDataReader drd=cmd.ExecuteReader();
            while (drd.Read())
            {
                Console.WriteLine(drd["MaQuay"].ToString());
                if (hoadon.maQT == drd["MaQuay"].ToString())
                    flag = true;
            }

            if (flag)
                hoadonDAO.InsertHoaDon(hoadon);
            else
                throw new Exception("Mã quầy thu không chính xác!");
        }

        public void UpdateHoaDon(HoaDon hoadon)
        {
            hoadonDAO.UpdateHoaDon(hoadon);
        }

        public void DeleteHoaDon(HoaDon hoadon)
        {
            hoadonDAO.DeleteHoaDon(hoadon);
        }

        public List<HoaDon> GetListHoaDon()
        {
            return hoadonDAO.GetListHoaDon();
        }

        public DataTable SelectAllHoaDon()
        {
            return hoadonDAO.SelectAllHoaDon();
        }
    }
}
